<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Project Manager</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <div class="container">
        <a class="navbar-brand" href="/projects">Project Manager</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link active" href="/projects">Projects</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/projects/new">New Project</a>
                </li>
            </ul>
        </div>
        <div class="d-flex">
                <span class="navbar-text text-white me-3">
                    <span th:text="${#authentication.name}">User</span>
                </span>
            <a href="/logout" class="btn btn-outline-light">Logout</a>
        </div>
    </div>
</nav>

<div class="container mt-5">
    <h1 class="mb-4">Project List</h1>

    <div class="d-flex justify-content-between mb-4">
        <div>
            <a href="/projects/new" class="btn btn-success">Create New Project</a>
        </div>
        <div>
            <form class="d-flex" role="search">
                <input class="form-control me-2" type="search" placeholder="Search projects" aria-label="Search">
                <button class="btn btn-outline-primary" type="submit">Search</button>
            </form>
        </div>
    </div>

    <div class="table-responsive">
        <table class="table table-bordered table-striped">
            <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Description</th>
                <th>Start Date</th>
                <th>End Date</th>
                <th>Manager</th>
                <th>Actions</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="project : ${projects}">
                <td th:text="${project.id}">1</td>
                <td th:text="${project.name}">Project Name</td>
                <td th:text="${project.description}">Project Description</td>
                <td th:text="${#dates.format(project.startDate, 'yyyy-MM-dd')}">2023-01-01</td>
                <td th:text="${#dates.format(project.endDate, 'yyyy-MM-dd')}">2023-12-31</td>
                <td th:text="${project.manager.username}">Manager</td>
                <td>
                    <a th:href="@{/projects/edit/{id}(id=${project.id})}" class="btn btn-sm btn-primary">Edit</a>
                    <a th:href="@{/projects/delete/{id}(id=${project.id})}" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this project?')">Delete</a>
                </td>
            </tr>
            </tbody>
        </table>
    </div>

    <div class="mt-4" th:if="${projects.empty}">
        <div class="alert alert-info">
            No projects found. Click "Create New Project" to add your first project.
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>